package com.vic.queue_param.arguments.x_max_length_bytes;

import com.rabbitmq.client.*;
import com.vic.utils.RabbitmqUtils;

import java.io.IOException;

public class Test_mlb_consumer {

    public static void main(String[] argv) throws Exception {
        Channel channel = RabbitmqUtils.getChannel();

        String queueName = "queue_x_max_length_bytes";

        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
            String message = new String(delivery.getBody(), "UTF-8");
            System.out.println("接收消息：" + message);
        };
        channel.basicConsume(queueName, true, deliverCallback, consumerTag -> { });

    }

    /**
     * 方式2
     * @param channel
     */
    private static void way2(Channel channel, String queueName) throws IOException {

        String consumerTag = "consumerTag";

        DefaultConsumer consumer = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {

                System.out.println("：" + new String(body));

            }
        };

        channel.basicConsume(queueName, true, consumerTag, consumer);
    }
}